package com.gitzzp.materialdesignsample;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.graphics.drawable.Animatable2;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        ((AnimatedVectorDrawableCompat)((AppCompatImageView)findViewById(R.id.image_svg)).getDrawable()).start();
        final AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable.vectalign_animated_vector_drawable_start_to_end);
        ImageView imageView = (ImageView) findViewById(R.id.image_svg);
        imageView.setImageDrawable(animatedVectorDrawable);
        animatedVectorDrawable.start();
        animatedVectorDrawable.registerAnimationCallback(new Animatable2.AnimationCallback() {
            @Override
            public void onAnimationEnd(Drawable drawable) {
                super.onAnimationEnd(drawable);
                animatedVectorDrawable.start();
            }
        });
    }


    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public Animator createAnimation(View v, boolean isFirst){
        Animator animator;

        if (isFirst) {
            animator = ViewAnimationUtils.createCircularReveal(
                    v,//操作的视图
                    0,//动画开始的X坐标
                    0,//动画开始的Y坐标
                    v.getWidth(),//动画开始的半径
                    0//动画结束时的半径
                    );
        }else {
            animator = ViewAnimationUtils.createCircularReveal(
                    v,
                    0,
                    0,
                    0,
                    v.getWidth()
                    );
        }
        animator.setInterpolator(new DecelerateInterpolator());
        animator.setDuration(500);
        return animator;
    }

    public void a(View v){
        ObjectAnimator.ofFloat(v,"translationZ",100).setDuration(1000);
    }

}
